package controller.web;

import dao.AccountTD;
import dao.UserMessageTD;
import org.apache.catalina.User;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import pojo.Account;
import util.Result;
@CrossOrigin
@Controller
@ResponseBody
@RequestMapping("/register")
public class RegisterController {
    @Autowired
    private AccountTD accountTD;
    @RequestMapping("/user")
    public Object createAccount(@RequestBody Account account){
        if(accountTD.selectPeopleById(account)==null){
            if(accountTD.createAccount(account.getId(),account.getPassword())){
                accountTD.insertUser(account.getId());
                return Result.success();
            }else{
                return Result.error("账号创建异常");
            }
        }
        return Result.error("账号已存在");
    }
}
